package com.taotao.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.taotao.common.pojo.EasyUIResult;
import com.taotao.mapper.ItemMapper;
import com.taotao.pojo.Item;
import com.taotao.pojo.ItemExample;
import com.taotao.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品管理Service
 *
 * @author Lorry
 * @date 2018/12/04 9:59
 */
@Service
public class ItemServiceImpl implements ItemService {
    @Autowired
    private ItemMapper itemMapper;

    @Override
    public Item getItemById(long itemId) {
        return itemMapper.selectByPrimaryKey(itemId);
    }

    /**
     * 商品列表查询
     *
     * @param page     页码
     * @param pageSize 每页条数
     * @return
     */
    @Override
    public EasyUIResult getItemList(int page, int pageSize) {
        ItemExample example = new ItemExample();
        PageHelper.startPage(page, pageSize);
        List<Item> items = itemMapper.selectByExample(example);
        PageInfo<Item> pageInfo = new PageInfo<>(items);

        return new EasyUIResult(pageInfo.getTotal(), items);
    }
}
